import moment from 'moment'

export default function (str, format) {
  let date
  if (!str) {
    return '-'
  } else if (typeof str === 'number') {
    // unix timastamp
    date = moment.unix(str)
  } else {
    date = moment(str)
  }
  if (!format) {
    format = 'YYYY-MM-DD HH:mm:ss'
  }
  return date.isValid() ? date.format(format) : '-'
}
